<?php
/**
 * Copyright 2010 Dave Keen
 * http://www.actionscriptdeveloper.co.uk
 * 
 * This file is part of Flextrine.
 * 
 * Flextrine is free software: you can redistribute it and/or modify
 * it under the terms of the Lesser GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Lesser GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * and the Lesser GNU General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 * 
 */

include "bootstrap.php";

include("services/FlextrineService.php");

$service = new FlextrineService();

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;

try {
	switch ($action) {
		case "generate":
			echo json_encode($service->generateAS3Entities());
			break;
		case "create":
			$service->createSchema();
			echo json_encode(array("success" => "Schema created successfully"));
			break;
		case "update":
			$service->updateSchema();
			echo json_encode(array("success" => "Schema updated successfully"));
			break;
		case "drop":
			$service->dropSchema();
			echo json_encode(array("success" => "Schema dropped successfully"));
			break;
		default:
			echo json_encode($service->getFlextrineManagerData());
			break;
	}
} catch (Exception $e) {
	echo json_encode(array("failure" => $e->getMessage()));
}

?>